<template>
  <div class="components-container">
    <sweet-modal ref="dialog" :sweetModalMaxWidth="1250">
      <h3 style="color:red;">{{title}}</h3>
      <el-main style="height:600px;">
        <div style="width:65%;height:100%;float:left">
          <el-card class="box-card" body-style="padding-left:0px;">
            <div class="layui-form-item">
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <!-- style="font-size:13px;padding:5px;" -->
                <label class="">业务编号</label>
                <div class="layui-inline">
                  <!-- size="small" -->
                  <el-input style="width:150px;" v-model="prpdata.PRPNO" placeholder="请输入业务编号" readonly></el-input>
                </div>
              </div>
              <div class="layui-inline" style="margin:0px;">
                <!-- style="font-size:13px;padding:5px;" -->
                <label class="">死者姓名</label>
                <div class="layui-inline">
                  <el-input style="width:150px;" v-model="prpdata.PRPDEADNAME" placeholder="请输入死者姓名" readonly></el-input>
                </div>
              </div>
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">性别</label>
                <div class="layui-inline">
                  <el-input style="width:80px;" v-model="prpdata.PRPDEADSEXDESC" placeholder="" readonly></el-input>
                </div>
              </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">接尸日期</label>
                <div class="layui-inline">
                  <el-date-picker style="width:150px;" v-date type="date" v-model="prpdata.CDHACTUALDATEDESC" readonly></el-date-picker>
                </div>
              </div>
              <div class="layui-inline" style="margin:0px;">
                <label class="">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄</label>
                <div class="layui-inline">
                  <el-input style="width:80px;" v-model="prpdata.PRPDEADAGE" placeholder="" readonly></el-input>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline" style="width:575px;margin-left:15px;">
                <label class="">接尸地址</label>
                <div class="layui-inline">
                  <el-input class="longertext" v-model="prpdata.CDHADDRESS" readonly></el-input>
                </div>
              </div>
            </div>
          </el-card>

          <el-card class="box-card" body-style="padding: 10px 0 0 0">
            <div class="layui-form-item">
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">到馆日期</label>
                <div class="layui-inline">
                  <el-date-picker style="width:150px;" v-date type="date" v-model="selectData.REGDATE" :readonly="!(status === 'A')"></el-date-picker>
                </div>
              </div>
              <div class="layui-inline" style="margin:0;">
                <label class="">到馆时间</label>
                <div class="layui-inline">
                  <el-time-picker style="width:150px;" v-date v-model="selectData.REGTIME" format='HH:mm:ss' :readonly="!(status === 'A')"></el-time-picker>
                </div>
              </div>
              <div class="layui-inline">
                    <label class="layui-form-label" style="text-align:center;padding:0;font-weight:700;">是否出具死亡证明</label>
                    <div class="layui-inline">
                        <el-select v-model="selectData.PRPISPOD" filterable disabled style="width:100px;">
                            <el-option v-for="item in choosearray" :key="item.Value" :label="item.Text" :value="item.Value" style="width:100px;">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
              <!-- <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">是否冷藏</label>
                <div class="layui-inline">
                  <el-select v-model="selectData.PRPISCODE" filterable style="width:100px;" @change="isicenum($event)" >
                    <el-option v-for="item in icestatus" :key="item.label" :label="item.value" :value="item.label"></el-option>
                  </el-select>
                </div>
              </div> -->
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">冰&nbsp;&nbsp;柜&nbsp;&nbsp;号</label>
                <div class="layui-inline">
                  <el-select v-model="selectData.ICHICEID" filterable style="width:100px;" @change="changeid('1')">
                    <el-option v-for="item in icenum" :key="item.ICEID" :label="item.ICENAME" :value="item.ICEID"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">灵堂号</label>
                <div class="layui-inline">
                  <el-select v-model="selectData.LIHLINID" filterable style="width:100px;" @change="changeid('2')">
                    <el-option v-for="item in linnum" :key="item.value" :label="item.label" :value="item.value"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="layui-inline" style="margin:0 0 0 15px;">
                <label class="">礼厅号</label>
                <div class="layui-inline">
                  <el-select v-model="selectData.MEHMEMID" filterable style="width:100px;" @change="changeid('3')">
                    <el-option v-for="item in memnum" :key="item.value" :label="item.label" :value="item.value"></el-option>
                  </el-select>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline" style="margin:0 0 0 15px;">
                    <label class="">死亡日期</label>
                    <div class="layui-inline">
                        <el-date-picker style="width:150px;" v-date type="date" v-model="prpdata.PRPDEATHDATE" :readonly="!(status === 'A')"></el-date-picker>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">统计地点</label>
                    <div class="layui-input-inline backcolor">
                        <el-cascader :options="area" v-model="carryArea" filterable :show-all-levels="false" :disabled="!(status === 'A')"></el-cascader>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-inline" style="width:575px;margin-left:15px;">
                <label class="">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
                <div class="layui-inline">
                  <el-input type="textarea" class="longertext" v-model="selectData.REGREMARK"></el-input>
                </div>
              </div>
            </div>
          </el-card>
          <el-card class="box-card" body-style="padding:0 10px 0 10px;" style="height:210px;">
            <div id="box" style="overflow:auto;height:210px;">
              <table class="layui-table scroll" style="border-spacing: 0;" ref="scroll">
                <colgroup>
                  <col width="180">
                  <col width="80">
                  <col width="110">
                  <col width="130">
                  <col>
                </colgroup>
                <thead>
                  <tr>
                    <th>费用名称</th>
                    <th>单位</th>
                    <th>数量</th>
                    <th>单价</th>
                    <th>金额</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody ref='inputs'>
                  <tr class="allRow" v-for="(chl,index) in chlList">
                    <td>
                      <el-select @change="chaSelect(index)" ref="select" v-model="chl.CHLCHAID" :disabled="isinfo" clearable @keydown.enter.native="enterEvent(index,0)" :filter-method="chaFilter" @visible-change="reset()" filterable>
                        <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID">
                        </el-option>
                      </el-select>
                    </td>
                    <td>
                      <el-input @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLAUNIT" readonly>
                        <!-- <template slot="append">元</template> -->
                      </el-input>
                      <!-- {{chl.DPTNAME}} -->
                    </td>
                    <td>
                      <el-input @input="changemoney(index,$event)" @keydown.enter.native="enterEvent(index,2)" v-model="chl.CHLNUM" :readonly="isinfo">
                        <!-- <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template> -->
                      </el-input>
                    </td>
                    <!-- 单价 -->
                    <td>
                      <el-input @input="changechlmoney(index,$event)"  @keydown.enter.native="enterEvent(index,3)" v-model="chl.CHLMONEY" :readonly="chl.CHALOGO === 'A'">
                        <template slot="append">元</template>
                      </el-input>
                    </td>
                    <td>
                      <el-input @keydown.enter.native="enterEvent(index,4)" v-model="chl.CHLMOUNT" :readonly="isinfo">
                        <template slot="append">元</template>
                      </el-input>
                    </td>
                    <!-- <td>
                            <el-input @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLACCOUNT" readonly>
                            </el-input>
                          </td> -->
                    <!-- <td>
                            <div class="layui-input-inline chooseTime">
                              <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="chl.CHLDATE"></el-date-picker>
                            </div>
                          </td> -->
                    <td>
                      <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)" :disabled="isinfo">
                        <i class="layui-icon">&#xe640;</i>
                      </button>
                    </td>

                  </tr>
                </tbody>
                <tfoot>
                  <tr>
                    <td>
                        <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()" :disabled="isinfo">
                            <i class="layui-icon">&#xe654;</i>
                        </button>
                    </td>
                    <td colspan="1">
                      <span>合计</span>
                    </td>
                    <td></td>
                    <td></td>
                    <td>{{ discountTotal }}</td>
                    <!-- <td></td>
                          <td></td> -->
                    <td></td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </el-card>
        </div>
        <div style="width:35%;height:100%;float:left">
          <el-card class="box-card" body-style="padding: 0 10px 0 10px;" style="height:570px;">
            <div :style="{maxHeight:maxHeights+'px'}" style="overflow:auto;">
              <table class="layui-table" style="border-spacing: 0;width: 600px;">
                <colgroup>
                  <col width="200">
                  <col width="200">
                  <col width="200">
                  <col>
                </colgroup>
                <thead>
                  <tr>
                    <th>类型</th>
                    <th>处理时间</th>
                    <th>内勤备注</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody ref='inputss'>
                  <tr class="allRows" v-for="(chls,index) in chlLists">
                    <td>
                      <el-select ref="select" v-model="chls.OFFCODNAME"  @change="changetime(chls)" clearable :filter-method="chaFilter" :disabled='isINFO' filterable>
                        <el-option v-for="item in QueryNolstaff" :key="item.Text" :label="item.Value" :value="item.Text">
                        </el-option>
                      </el-select>
                    </td>
                    <td>
                      <div class="layui-input-inline chooseTime">
                        <el-date-picker style="width:180px;float:left;" v-date clear-icon="null" type="datetime" format="yyyy-MM-dd HH:mm" v-model="chls.OFFCHKDATE" @change="changetime(chls)"></el-date-picker>
                      </div>
                    </td>
                    <td>
                      <el-input v-model="chls.OFFDESC" :readonly="isinfo">
                      </el-input>
                    </td>
                    <td>
                      <button class="layui-btn layui-btn-small layui-btn-normal" @click="removes(index)" :disabled='isINFO'>
                        <i class="layui-icon">&#xe640;</i>
                      </button>
                    </td>
                  </tr>
                </tbody>
                <tfoot>
                  <tr>
                    <td>
                      <button class="layui-btn layui-btn-small layui-btn-normal" @click="inserts()" :disabled='isINFO'>
                        <i class="layui-icon">&#xe654;</i>
                      </button>
                    </td>
                    <td colspan="3"></td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </el-card>
        </div>
      </el-main>
      <el-footer style="height:50px;lint-height:50px;">
        <el-card class="box-card btnCenter" body-style="padding:10px;">
          <el-button type="primary" icon="el-icon-document" size="small" style="margin-left:50px;" @click="submit">保存</el-button>
          <el-button type="primary" icon="el-icon-close" size="small" style="margin-left:220px;" @click="closeDialog">关闭</el-button>
        </el-card>
      </el-footer>
    </sweet-modal>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
.el-button + .el-button {
    margin-left: 0;
}

.longtext {
    width: 480px;
}

.longertext {
    width: 480px;
}

.sweet-btn {
    margin-top: 20px;
}
</style>
<script>
import apiBase from "@/api/apiBase.js";
import sweetModal from "@/components/sweetModal";
import {
    formatDate,
    timeStringToDate,
    dateStringToDate
} from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { accMul, Subtr, accAdd } from "@/utils/operations.js";
import $ from 'jquery'
const MODIFY = "新增";
const Detail = "详情";
export default {
    mixins: [manage],
    data() {
        return {
            pageWidth: 1250,
            maxHeight: 210,
            maxHeights: 570,
            title: null,
            ids: null,
            szlx: [],
            icenum: [], //冰柜号
            linnum: [], //灵堂号
            memnum: [], //礼厅号
            checked: null,
            isice: null, //是否能选择冰柜号
            chlList: [],
            chlLists: [],
            chaList: [], //费用名称
            QueryNolstaff: [],
            isinfo: null,
            isINFO: false,
            status: null,
            showtongji:false,
            area: [],
            carryArea: [],
            selectData: {
                REGDATE: new Date(), //日期
                REGTIME: new Date(), //时间
                REGREMARK: null, //备注
                ICHICEID: null, //冰柜号
                MEHMEMID: null, //礼厅号
                LIHLINID: null, //灵堂号
                PRPISCODE: null, //是否冷藏
                PRPISPOD: null, //是否出具死亡证明
            },
            chl: {
                CHLCHAID: null, //名称
                CHLAUNIT: null, //单位
                CHLNUM: null, //数量
                CHLMONEY: null, //单价
                CHLMOUNT: null //金额
            },
            cdhActualDateTime: null,
            chls: {
                OFFCODNAME: null,
                OFFDESC: null,
                OFFCHKDATE: null,
                OFFCHKTIME: null,
            },
            choosearray: [
                {Value: 'B',Text: '是'},
                {Value: 'A',Text: '否'}
            ],
            icestatus: [
                {
                    label: "A",
                    value: "否"
                },
                {
                    label: "B",
                    value: "是"
                }
            ],
            prpdata: {
                PRPDEATHDATE: null,
                Cdh: {
                    CDHACTUALDATEDESC: null,
                    CDHADDRESS: null
                }
            },
            cdh:null,
            regDataEexend: {
            regDataTime: null,
            }
            
        };
    },
    methods: {
        //义乌特殊需求 
        changetime(chls){
            if(chls.OFFCHKDATE!=null){
                if(chls.OFFCODNAME=="直进冰箱"||chls.OFFCODNAME=="直进灵堂"){
                this.selectData.REGDATE= chls.OFFCHKDATE
                this.selectData.REGTIME= chls.OFFCHKDATE
                }    
            }
        },
      //禁用已选项 义乌
    //   disabled(chaID) {
    //     let retVal = this.chlList.some(item => {
    //       return item.CHLCHAID === chaID;
    //     });
    //     return retVal;
    //   },
        //获取数据的事件合集
        events() {
            this.cdhActualDateTime = new Date();
            this.selectData.REGDATE = formatDate(new Date(), "yyyyMMdd");
            this.selectData.REGTIME = new Date();
            // this.geticenum(); //获取冰柜号
            this.getpeopledata(); //获取个人信息
            this.getAllCharge(); //获取费用名称
            this.gettype(); //获取内勤类型
        },
        open(order, id, status) {
            this.ids = id;
            this.status = status;
            this.order = order;
            this.events();
            this.dataRepeat();
            switch (this.order) {
                case MODIFY:
                    this.title = "内勤登记信息";
                    setTimeout(() => {
                        this.insert();
                    }, 200);
                    
                    this.inserts();
                    this.$refs.dialog.open();
                    break;
                // case Detail:
                //     this.title = "详情";
                //     this.dataInfo(id);
                //     this.$refs.info.open();
                //     break;
                default:
            }
        },
        //回车事件
        enterEvent(rowNum, colNum) {
            //获取所有行
            let rows = this.$refs.inputs.getElementsByClassName("allRow");
            //获取当前行
            let currow = rows[rowNum];
            // 获取当前行所有列
            let inputs = currow.getElementsByTagName("input");
            //强制隐藏下拉框
            if (colNum === 0) {
                let chl = this.chlList[rowNum];
                if (chl.CHLCHAID == null) {
                    this.$message({
                        type: "error",
                        message: `第${parseInt(rowNum) + 1}行收费项目不能为空!`
                    });
                    return;
                }
                let select = this.$refs.select;
                select[rowNum].visible = false;
            }
            //最后一列
            if (colNum === inputs.length - 1) {
                //最后一行
                if (rowNum === this.chlList.length - 1) {
                    //插入空行
                    if (!this.insert()) {
                        return;
                    }
                }
                //换行
                this.$nextTick(function() {
                    this.enterEvent(rowNum + 1, -1);
                });
            } else {
                //获取下一个焦点
                this.$nextTick(function() {
                    inputs[colNum + 1].select();
                });
            }
        },
        remove(index) {
            this.chlList.splice(index, 1);
        },
        removes(index) {
            this.chlLists.splice(index, 1);
        },
        //自定义筛选
        chaFilter(val) {
            this.chaList = JSON.parse(JSON.stringify(this.allCharge));
            if (val) {
                if (val.length > 0)
                    this.chaList = this.allCharge.filter(item => {
                        return (
                            item.CHANAME.indexOf(val) > -1 ||
                            item.CHADM.toLowerCase().indexOf(
                                val.toLowerCase()
                            ) > -1
                        );
                    });
            }
        },
        reset() {
            this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        },
        //新增行
        insert() {
            for (let index in this.chlList) {
                let chl = this.chlList[index];
                if (chl.CHLCHAID.null === 0) {
                    this.$message({
                        type: "error",
                        message: `第${parseInt(index) + 1}行收费项目不能为空!`
                    });
                    return false;
                }
            }
            this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
            setTimeout(() => {
                let tableHeight = this.$refs.scroll.scrollHeight;
                $("#box").animate({scrollTop:tableHeight},500);
            }, 100);
            
            return true;
        },
        getAddr() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Code.GetAddressMap,
                res => {
                let cardata = res.data.content;
                this.area = cardata.map(item => ({
                    value: item.ADDID,
                    label: item.ADDNAME,
                    ADDLEVEL: item.ADDLEVEL,
                    ADDTOPID: item.ADDTOPID,
                    children: item.Children.map(itemStr => ({
                    value: itemStr.ADDID,
                    label: itemStr.ADDNAME,
                    ADDLEVEL: itemStr.ADDLEVEL,
                    ADDTOPID: itemStr.ADDTOPID
                    }))
                }));
                       //义乌个性化负默认值
                    if(this.showtongji){
                        if(this.area){
                            this.carryArea=[this.area[0].value,this.area[0].children[0].value]
                        }
                    }
                }
            );
        },
        changeid(num){
            switch(num){
                case '1':
                    this.selectData.LIHLINID = null;
                    this.selectData.MEHMEMID = null;
                    break;
                case '2':
                    this.selectData.ICHICEID = null;
                    this.selectData.MEHMEMID = null;
                    break;
                case '3':
                    this.selectData.ICHICEID = null;
                    this.selectData.LIHLINID = null;
                    break;
                default:
            }
        },
        //新增行
        inserts() {
            for (let index in this.chlLists) {
                let chls = this.chlLists[index];
                if (chls.OFFCODNAME === null) {
                    this.$message({
                        type: "error",
                        message: `第${parseInt(index) + 1}行类型不能为空!`
                    });
                    return false;
                }
            }
            this.chlLists.push(JSON.parse(JSON.stringify(this.chls)));

            return true;
        },
        //选择收费项目
        chaSelect(index) {
            // chl.CHLNUM
            let chl = this.chlList[index];
            let cha = this.getChaByID(chl.CHLCHAID);
            if (cha) {
                chl.CHLAUNIT = cha.CHAAUNIT;
                chl.CHLMONEY = cha.CHAMONEY;

                chl.CHLCHAID = cha.CHAID;
                chl.CHLDISCOUNT = cha.CHADISCOUNT;
                chl.CHLDM = cha.CHADM;
                chl.CHLHIDISCOUNT = cha.CHAHIDISCOUNT;
                chl.CHLJMHIMONEY = cha.CHAJMHIMONEY;
                chl.CHLJMMONEY = cha.CHAJMMONEY;
                chl.CHLNAME = cha.CHANAME;
                chl.CHLPRICE = cha.CHAPRICE;
                chl.CHLNUM = 1;
                chl.CHLMOUNT = cha.CHAMONEY;

            }
        },
        //ID获取收费项目
        getChaByID(chaId) {
            for (var i in this.allCharge) {
                var cha = this.allCharge[i];
                if (cha.CHAID === chaId) {
                    return cha;
                }
            }
        },
        //控制是否选择冰柜号
        isicenum(val) {
            if (val === "B") {
                this.isice = false;
            } else {
                this.isice = true;
                this.selectData.ICHICEID = null;
            }
        },
        //计算金额
        changemoney(index, num) {
            let chl = this.chlList[index];
            chl.CHLMOUNT = Number(num) * Number(chl.CHLMONEY);
        },
        changechlmoney(index, money){
            let chl = this.chlList[index];
            chl.CHLMOUNT = Number(chl.CHLNUM) * Number(money);
        },
        //收费项目
        getAllCharge() {
            let data = {
                SOURCE: '内勤管理'
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Checkout.GetChargeBySource,
                res => {
                    this.allCharge = res.data.content;
                    this.chaList = JSON.parse(JSON.stringify(this.allCharge));
                }
            );
        },
        //获取冰柜号
        geticenum(id) {
            let data = {
                ICEID: id
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().IceUse.QueryIceBynotuse,
                res => {
                    this.icenum = res.data.content;
                }
            );
        },
        //获取灵堂号
        getlinnum(id) {
            let data = {
                LINID: id
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().MourningUse.QueryUnusedMourning,   
                res => {
                    let caudata = res.data.content;
                    this.linnum = caudata.map(item => ({
                        label: item.LINNAME,
                        value: item.LINID,
                    }));
                }
            );
        },
        //获取礼厅号
        getmemnum(id) {
            let data = {
                MEMID: id
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().MemorialUse.QueryUnusedMemorial,
                res => {
                    let caudatas = res.data.content;
                    this.memnum = caudatas.map(item => ({
                        label: item.MEMNAME,
                        value: item.MEMID,
                    }));
                }
            );
        },
        //获取类型
        gettype() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Internalduty.GetOffType,
                res => {
                    this.QueryNolstaff = res.data.content;
                }
            );
        },
        //获取个人信息
        getpeopledata() {
            let data = {
                REGID: this.ids
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Internalduty.Detail,   
                res => {
                    //获取个人信息
                    this.prpdata.PRPNO = res.data.content.PRPNO;
                    this.prpdata.PRPDEADNAME = res.data.content.PRPDEADNAME;
                    this.prpdata.PRPDEADSEXDESC = res.data.content.PRPDEADSEXDESC;
                    this.prpdata.PRPDEADAGE = res.data.content.PRPDEADAGE;
                    this.prpdata.CDHADDRESS = res.data.content.PRPCORPSEADDRESS;
                    this.prpdata.PRPDEATHDATE = res.data.content.PRPDEATHDATE;
                    this.prpdata.REGPRPID = res.data.content.REGPRPID;
                    if (res.data.content.Cdh) {
                        this.prpdata.CDHACTUALDATEDESC = res.data.content.Cdh.CDHACTUALDATEDESC;
                        this.cdh = res.data.content.Cdh
                    }
                    // *********************************
                    this.selectData.PRPISCODE = res.data.content.PRPISCODE;//获取是否冷藏
                    this.selectData.REGREMARK = res.data.content.REGREMARK;//获取备注
                    if(res.data.content.REGDATEDESC){
                    this.selectData.REGDATE = res.data.content.REGDATEDESC;//获取日期
                    }
                    if(res.data.content.REGTIMEDESC){
                    this.selectData.REGTIME = timeStringToDate(res.data.content.REGTIMEDESC);//获取时间
                    }else{
                         this.selectData.REGTIME = new Date()//获取时间
                    }
                    this.selectData.PRPISPOD = res.data.content.PRPISPOD;//获取是否出具死亡证明


                    if (res.data.content.Ich) {
                        this.selectData.ICHICEID = res.data.content.Ich.ICHICEID;
                    }
                    if (res.data.content.Lih) {
                        this.selectData.LIHLINID = res.data.content.Lih.LIHLINID;
                    }
                    if (res.data.content.Meh) {
                        this.selectData.MEHMEMID = res.data.content.Meh.MEHMEMID;
                    }
                    if (res.data.content.list_Chl) {
                        // this.prpdata.ICHICEID = res.data.content.Ich.ICENO;
                        this.chlList = res.data.content.list_Chl;
                    }
                    if (res.data.content.list_Off) {
                        // this.prpdata.ICHICEID = res.data.content.Ich.ICENO;
                        this.chlLists = res.data.content.list_Off; 
                        this.chlLists.forEach(item => {
                            item.OFFCHKDATE = timeStringToDate(
                                item.OFFCHKTIME,
                                item.OFFCHKDATE
                            )
                        });
                        // this.chlLists.OFFCHKDATE = timeStringToDate(
                        //     this.chlLists.OFFCHKDATE,
                        //     this.chlLists.OFFCHKTIME
                        // );
                    }
                    this.geticenum(this.selectData.ICHICEID);
                    this.getlinnum(this.selectData.LIHLINID);
                    this.getmemnum(this.selectData.MEHMEMID);
                    this.getAddr();
                    if (this.selectData.PRPISCODE === "B") {
                        this.isice = false;
                    } else {
                        this.isice = true;
                    }
                }
            );
        },
        lalala() {
            this.$refs.lalala.open();
        },
        getSum(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计";
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (column.property === "address") {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index];
                } else {
                    sums[index] = "--";
                }
            });
            return sums;
        },
        closeDialog() {
            this.$refs.dialog.close();
        },
        //提交
        submit() {
            switch (this.order) {
                case MODIFY:
                    this.dataModify();
                    break;
                default:
            }
        },
        dataModify() { 
            let data = JSON.parse(JSON.stringify(this.selectData));
            let chlList = JSON.parse(JSON.stringify(this.chlList));
            let chlLists = JSON.parse(JSON.stringify(this.chlLists));
            if (this.selectData.REGDATE) {
                data.REGDATE = formatDate(this.selectData.REGDATE, "yyyyMMdd");
            }
            if (this.selectData.REGTIME) {
                data.REGTIME = formatDate(this.selectData.REGTIME, "hhmmss");
            }
            if (data.ICHICEID) {
                var list = { ICHICEID: data.ICHICEID };
                data.Ich = list;
            } else {
                data.Ich = {};
            }
            if (data.LIHLINID) {
                var lists = { LIHLINID: data.LIHLINID };
                data.Lih = lists;
            } else {
                data.Lih = {};
            }
            if (data.MEHMEMID) {
                var lista = { MEHMEMID: data.MEHMEMID };
                data.Meh = lista;
            } else {
                data.Meh = {};
            }
            if (data.PRPISCODE) {
                var list = { PRPISCODE: data.PRPISCODE };
                data.prp = list;
            } else {
                data.prp = {};
            }
            if (chlList.length > 0) {
                chlList.forEach((item,index) => {
                    if(item.CHLCHAID == null){
                        chlList.splice(index,1);
                    }
                });
                data.list_Chl = chlList;
            }
            if (chlLists.length > 0) {
                chlLists.forEach(item => {
                    item.OFFCHKTIME = formatDate(item.OFFCHKDATE, "hhmmss");  
                    item.OFFCHKDATE = formatDate(item.OFFCHKDATE, "yyyyMMdd");
                });
                data.list_Off = chlLists;

            }
            data.REGID = this.ids;

            if(!data.REGDATE){
                this.$message({
                    type: "error",
                    message: "请输入到馆日期！"
                });
                return
            }
            if(!data.REGTIME){
                this.$message({
                    type: "error",
                    message: "请输入到馆时间！"
                });
                return
            }
            // apiBase.DoService(
            //     data,
            //     apiBase.getApiAdress().Internalduty.Modify,
            //     res => {
            //         this.$refs.dialog.close();
            //         this.$message({
            //             type: "success",
            //             message: "修改成功!"
            //         });
            //         this.refreshData();
            //     }
            // );
            if(this.status == "A"){
                apiBase.DoService(
                    {
                      REGZSLOGO:'A',
                      REGISKEYPOINT: "B",
                      REGBONETYPE: "其他",
                      InternalCreate: '内勤管理',
                      REGPRPID: this.prpdata.REGPRPID,
                      REGADDID: this.carryArea[this.carryArea.length - 1], 
                      REGDEATHDATE: formatDate(this.prpdata.PRPDEATHDATE, "yyyyMMdd"),
                      REGDEATHDATE: formatDate(this.prpdata.PRPDEATHDATE, "yyyyMMdd"),
                      REGDEATHDATE: formatDate(this.prpdata.PRPDEATHDATE, "yyyyMMdd"),
                      REGDATE :formatDate(this.selectData.REGDATE, "yyyyMMdd"),
                      REGTIME :formatDate(this.selectData.REGTIME, "hhmmss"),
                      Cdh:this.cdh
                    },
                    apiBase.getApiAdress().Registration.CremationRegistration_YW,
                    res => {
                        apiBase.DoService(
                            data,
                            apiBase.getApiAdress().Internalduty.Modify,
                            res => {
                                this.$refs.dialog.close();
                                this.$message({
                                    type: "success",
                                    message: "修改成功!"
                                });
                                this.refreshData();
                            }
                        );
                    }
                );
            }else{
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Internalduty.Modify,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            type: "success",
                            message: "修改成功!"
                        });
                        this.refreshData();
                    }
                );
            }
            
        },
        dataInfo(id) {
            this.reg.REGID = id;
            let Data = JSON.parse(JSON.stringify(this.reg));
            apiBase.DoService(
                Data,
                apiBase.getApiAdress().NumBinding.Detail,
                res => {
                    this.regData = res.data.content;

                    this.regDataEexend.regDataTime = timeStringToDate(
                        this.regData.REGTIME,
                        this.regData.REGDATE
                    );
                    this.regDataEexend.regDeathDate = dateStringToDate(
                        this.regData.REGDEATHDATE
                    );
                    this.regDataEexend.RegBirthDate = dateStringToDate(
                        this.regData.REGBIRTHDATE
                    );
                    this.regDataEexend.regCremationDate = dateStringToDate(
                        this.regData.REGCREMATIONDATE
                    );
                    let cdhdata = this.regData.Cdh;
                    if (cdhdata) {
                        this.cdhdataEexend.cardata = [
                            cdhdata.CARCODNAME,
                            cdhdata.CDHCARID
                        ];
                        this.cdhdata.CARLIC = cdhdata.CARLIC;
                        this.cdhdata.CDHDRIVER = cdhdata.CDHDRIVER;
                        this.cdhdata.CDHMILEAGE = cdhdata.CDHMILEAGE;
                        this.cdhdata.STANAME = cdhdata.STANAME;
                    }
                }
            );
        },
        dataRepeat() {
            // this.prpDatas.PRPCREMATIONTIME = null;
            this.selectData.REGDATE = new Date();
            this.chlList = [];
            this.chlLists = [];
            Object.assign(
                this.$data.selectData,
                this.$options.data().selectData
            );
        },
        refreshData() {
            this.$emit("refreshData");
        }
    },
    components: {
        sweetModal
    },
    //计算属性
    computed: {
        discountTotal() {
            let total = 0;
            for (let chl of this.chlList) {
                total = accAdd(total, chl.CHLMOUNT);
            }
            return total;
        }
    },
    created() {
          //是否默认统计地点（义乌默认）
        apiBase.DoService(
            {},
            apiBase.getApiAdress().Param.GetIsDefaultAddid,
            res => {
                this.showtongji = res.data.content;
            }
        );
    },
//     watch: {
//     "selectData.REGDATE": function(val) {
//       this.selectData.REGDATE = formatDate(val, "yyyyMMdd");
//       this.selectData.REGTIME = formatDate(val, "hhmmss");
//     },
//   }
};
</script>
